#Andrew Gooch
#April 11, 2017
#Ripping Yarn, Political Communications
#Replication R file 9: Sample sizes for in-text and appendix references

#This R file is simply used to output sample sizes by party ID due to random assignment into control or treatment

#required packages
library(arm)
library(ggplot2)
library(grid)
library(gridExtra)
library(foreign)
library(survey)



######################
### MAY
######################

May15 <- read.dta("C:/Users/agooch/Dropbox/Dissertation/Data/Experiments/Aggregated Dataset/51512.dta")
attach(May15)

names(May15)


# overall treatment n sizes, nonresponse = 6
table(May15$Gtreatment)
table(May15$Gcontrol)
table(May15$Gcue)
table(May15$Ggoodjust)


#overall favorability, nonresponse = 6
table(May15$Gfavor)

#####################
# by PID, independent leaners are coded as partisans

#pid for newer question wording
table(May15$Gpid3)
May15$pid5_new <- May15$Gpid3
May15$pid5_new[May15$Gpid3 == 1] <- -1 #dem
May15$pid5_new[May15$Gpid3 == 2] <-  1#rep
May15$pid5_new[May15$Gpid3 == 3] <- 0 #ind
May15$pid5_new[May15$Gpid3 == 4] <- 0 #other
table(May15$pid5_new)


table(May15$Gindlean)
May15$leaner_new <- May15$Gindlean
May15$leaner_new[May15$Gindlean == 1] <- -1 #lean dem
May15$leaner_new[May15$Gindlean == 2] <-  1#lean rep
May15$leaner_new[May15$Gindlean == 3] <- 0 #neither
table(May15$leaner_new)


#3-point with leaners as partisans
May15$PID3_lean_new <- May15$leaner_new
May15$PID3_lean_new[May15$leaner_new== -1 | May15$pid5_new == -1] <- 1 #dem
May15$PID3_lean_new[May15$leaner_new== 0] <- 0 #ind
May15$PID3_lean_new[May15$leaner_new== 1 | May15$pid5_new == 1] <- -1 #rep
table(May15$PID3_lean_new)
table(May15$PID3_lean_new, May15$pid5_new)
table(May15$PID3_lean_new, May15$leaner_new)


# pid treatment and favorability n sizes, nonresponse = 6

#Democrats
table(May15$Gcontrol[May15$PID3_lean_new==1])
43+31+19+10+4+28  

table(May15$Ggoodjust[May15$PID3_lean_new==1])
60+50+18+3+4+14 

table(May15$Gcue[May15$PID3_lean_new==1])
47+42+20+11+4+39 

table(May15$Gfavor[May15$PID3_lean_new==1])
70+153+118+25+15+66 

#Republicans
table(May15$Gcontrol[May15$PID3_lean_new==-1])
26+34+24+17+6+27 

table(May15$Ggoodjust[May15$PID3_lean_new==-1])
24+35+12+20+15+24  

table(May15$Gcue[May15$PID3_lean_new==-1])
17+22+26+14+14+46

table(May15$Gfavor[May15$PID3_lean_new==-1])
16+20+67+87+155+58 

#Independents
table(May15$Gcontrol[May15$PID3_lean_new==0])
16+10+10+7+1+15 

table(May15$Ggoodjust[May15$PID3_lean_new==0])
8+12+8+3+1+9

table(May15$Gcue[May15$PID3_lean_new==0])
14+11+10+3+3+19 

table(May15$Gfavor[May15$PID3_lean_new==0])
6+11+54+18+23+48 







